btc(stratum): memoize per-job tx_data hex (H5 work_source.cpp:634 churn fix) - #124
Merged
Conversation
…rn fix) build_connection_coinbase rebuilt the per-job tx-hex vector on every call, even when the mempool tx set was unchanged -- the dominant churn/leak site in the 2026-06-02 heaptrack (work_source.cpp:634, ~768MB across 1.2M calls). Factor the rebuild into a standalone, unit-testable seam (btc/stratum/tx_data_memo.hpp) that memoizes the shared_ptr in a single slot keyed to a fingerprint over the merkle leaf set (wd->m_hashes, in leaf order). A repeat call against the same tx set returns the cached shared_ptr (a refcount bump) instead of re-serializing the whole mempool. The key is the exact leaf set that built this job merkle, so a hit is atomic-with-merkle by construction (no stale-tx-vs-fresh-merkle mismatch on submit). Single slot => bounded memory (one tx set retained), self-evicting on tx-set roll. Rewire build_connection_coinbase to call the seam, guarding the two new memo members (tx_data_fp_, tx_data_memo_) with template_mutex_ since the builder runs on connection threads. Adds a standalone acceptance harness (tx_data_memo_test.cpp) proving pointer-identity reuse, correct invalidation on tx-set change, content correctness, and O(1) per-call cost on the unchanged path. BTC-only; no behavioral change to other coins.
frstrtr
force-pushed
the
btc/h5-tx-data-memo-seam
branch
from
June 17, 2026 13:04
cff36c5 to
5a6d2aa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Follow-up to the H5 tx_data retention work: lands the
tx_data_memoseam + acceptance test + thework_source.cpprewire as a distinct, additive PR offmaster(kept separate from #123, which stays segwit-SSOT-only).build_connection_coinbaserebuilt the per-job tx-hex vector on every call, even when the mempool tx set was unchanged — the dominant churn/leak site in the 2026-06-02 heaptrack (work_source.cpp:634, ~768 MB across 1.2M calls).How
src/impl/btc/stratum/tx_data_memo.hpp— standalone, unit-testable seam. Memoizes theshared_ptrin a single slot keyed to a fingerprint over the merkle leaf set (wd->m_hashes, in leaf order). A repeat call against the same tx set returns the cachedshared_ptr(a refcount bump) instead of re-serializing the whole mempool. The key is the exact leaf set that built this job merkle, so a hit is atomic-with-merkle by construction (no stale-tx-vs-fresh-merkle mismatch on submit). Single slot ⇒ bounded memory (one tx set retained), self-evicting on tx-set roll.work_source.cpp— rewires the a1 block to call the seam; guards the two new memo members (tx_data_fp_,tx_data_memo_) withtemplate_mutex_since the builder runs on connection threads (the call site does not otherwise hold it).work_source.hpp— adds the two memo members next totemplate_mutex_.src/impl/btc/test/tx_data_memo_test.cpp— standalone acceptance harness (style oftemplate_parity_test.cpp, no btc/test CMake plumbing): proves pointer-identity reuse, correct invalidation on tx-set change, content correctness, and O(1) per-call cost on the unchanged path.Scope / posture